import flash.events.MouseEvent;

import mx.controls.ToolTip;
import mx.managers.ToolTipManager;
import mx.utils.ObjectUtil;

/**
 * Draw episode list menu
 * 
 * @param e
 */
private function popUpMenuEpisodeList(e:MouseEvent):void{ 
	// get data
	var item:Object = e.target.parent.data;

	if(item == null) 
		return;
	
	// new menu
	var root:NativeMenu = new NativeMenu();
	
	var showLink:NativeMenuItem = new NativeMenuItem("Ссылка на видео");
	showLink.addEventListener(Event.SELECT, function(e:Event):void{
		Alert.show(item.url, "Ссылка на видео");
	});
	root.addItem(showLink);
	
	/*var separateSub2:NativeMenuItem = new NativeMenuItem("-", true);
	root.addItem(separateSub2);*/
	
	var downloadVideo:NativeMenuItem = new NativeMenuItem("Скачать видео");
	downloadVideo.addEventListener(Event.SELECT, function(e:Event):void{
		download_manager.addFile(item.title+"."+item.hd_text+".mp4", item.url, item.title);
		createBubble("Загрузка добавлена в очередь");
	});
	root.addItem(downloadVideo);
	
	// assign native menu
	root.display(stage, e.stageX - 75, e.stageY);
}


/**
 * Creates notify bubble 
 */
private function createBubble(text:String):void{
	// create bubble var
	var completeTip:ToolTip = new ToolTip();
	// calc x and y
	var x:int = 10;
	var y:int = 55;
	
	// create bubble
	completeTip = ToolTipManager.createToolTip(text, x, y) as ToolTip;
	completeTip.setStyle("backgroundAlpha", "1.0");
	completeTip.setStyle("backgroundColor", "#354F98");
	completeTip.setStyle("color", "#FFFFFF");
	completeTip.setStyle("shadowColor", "#000000");
	completeTip.setStyle("borderColor", "#CE2929");
	completeTip.setStyle("cornerRadius", "0");
	completeTip.setStyle("fontSize", "12");
	completeTip.width += 20;
	
	// init hide timer
	var hideTimer:Timer = new Timer(3000,1);
	hideTimer.addEventListener(TimerEvent.TIMER_COMPLETE, function():void{
		// remove bubble
		ToolTipManager.destroyToolTip(completeTip);
		// erase vars
		hideTimer = null;
		completeTip = null;
	});
	// start timer
	hideTimer.start();
}